import { del } from '@/apis/InterviewQuestions'
import { notification, message } from 'ant-design-vue'
import type { Ref } from 'vue'

export function useInterviewQuestionsDel(
  entityName: string,
  searchFunc: () => void,
  loading: Ref<boolean>,
) {
  async function onDelete(id?: number) {
    if (!id) return
    loading.value = true
    try {
      const res = await del(id)
      if (res.data) {
        message.success(`删除${entityName}成功!`)
        loading.value = false
        searchFunc()
        return
      } else {
        notification.error({ message: `删除${entityName}失败!` })
      }
    } catch (error) {
      notification.error({
        message: `删除${entityName}失败!`,
      })
    }
    loading.value = false
  }
  return { onDelete }
}
